<div id="div2_chart"></div>
<script>
    var kategori = [];
    var series = [];
    var kat = [];
    var ser = [];
<?php

function format_angka($angka) {
    $len = strlen($angka);
    $res = "";
    $c = 0;
    while ($len > 0) {
        $len--;
        $res = $angka[$len] . $res;
        $c = ($c + 1) % 3;
        if ($c == 0 && $len > 0)
            $res = "." . $res;
    }
    return $res;
}

//var_dump($data);
$counter = 0;
foreach ($data as $pekerjaan) {
    $counter++;
    ?>
        ser.push(["<?= $pekerjaan->kategori ?>",<?= $pekerjaan->jumlah ?>]);
    <?php
}
?>

    $('#div2_chart').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 0, //null,
            plotShadow: false
        },
        title: {
            text: '<?= $judul ?>'
        },
        subtitle: {
            text: '<?php if (isset($subtitle))
    echo implode('-', $subtitle);
else
    echo 'Banyuwangi';
?>'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.y}</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
                type: 'pie',
                name: 'Jumlah',
                data: ser
            }]
    });

</script>
<div style="margin-top: 40px">
    <table class="table table-striped">
        <tr>
            <th>No</th>
            <th><?= $kolom ?></th>
            <th style="text-align: right">Jumlah</th>
            <?php
            $session = $this->session->userdata('login');
            $logged_in = false;
            if ($session != null) {
                $logged_in = true;
            }
            $logged_in&=isset($controller);
            if ($logged_in) {
                ?>
                <th style="text-align: right">Aksi</th>
            <?php
        }
        ?>
        </tr>
        <?php
        $tot = 0;
        $no = 0;
        foreach ($data as $row) {
            $no++;
            $tot = $tot + $row->jumlah;
            ?>
            <tr>
                <td><?= $no ?></td>
                <td><?= $row->kategori; ?></td>
                <td style="text-align: right"><?= format_angka($row->jumlah); ?></td>
                <?php
                if ($logged_in) {
                    ?>
                    <td style="text-align: right"><a href="<?= site_url() . '/' . $controller ?>?<?php if(isset($id_kecamatan)&&$id_kecamatan>0){echo 'id_kecamatan='.$id_kecamatan.'&';} if(isset($id_kelurahan)&& $id_kelurahan>0){echo 'id_kelurahan='.$id_kelurahan.'&';} ?>key=<?= $row->kategori_id ?>">Lihat</a></td>
                    <?php
                }
                ?>
            </tr>
            <?php
        }
        ?>
        <tr>
            <td></td>
            <td>Total</td>
            <td style="text-align: right"><?= format_angka($tot . ""); ?></td>
            <?php
                if ($logged_in) {
                    ?>
                    <td></td>
                    <?php
                }
                ?>
        </tr>
    </table>
</div>